package com.zust.data.web.controller;

import com.zust.data.dto.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @author shixiaoting
 * @date 2016年10月10日  下午7:34:59
 */
//@RestController
@RequestMapping("/user")
@Controller
public class HelloController {


    @Value("${application.message:你好}")
    private String message = "hi,hello world......";

    @RequestMapping("/hello")
    public ModelAndView test(Map<String, Object> model) throws Exception {
        ModelAndView mv = new ModelAndView("helloworld"); //返回的view就是templetes下面文件的名称
        model.put("time", new Date());
        model.put("message", this.message);
        List<User> users = new ArrayList<User>();
        User user2 = new User("test", "test", 0, 23, new Date());
        User user1 = new User("admin", "admin", 1, 23, new Date());
        User user3 = new User("super", "super", 1, 23, new Date());
        users.add(user1);
        users.add(user2);
        users.add(user3);
        System.out.println(users.size());
        mv.addObject("title", "Spring MVC And Freemarker");
        mv.addObject("content", " Hello world ， test my first spring mvc ! ");
        mv.addObject("users", users);
        return mv;
    }
}